package org.infosys.hello01;

import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;

import java.nio.charset.StandardCharsets;

/**
* @Description: 准备生产者
* @Author: hank
* @Version: 1.0
* @Date:  2022/7/27 1:21
*/
public class Producer {

    public static void main(String[] args) throws Exception {
        // 创建生产者对象
        DefaultMQProducer producer = new DefaultMQProducer("producer_hello_group");
        // 连接mq
        producer.setNamesrvAddr("127.0.0.1:9876");
        // 启动生产者
        producer.start();
        // 创建消息体
        Message message = new Message("hello_topic", "hello_tags", "我在源码学习Java!".getBytes(StandardCharsets.UTF_8));
        // 发送消息
        SendResult send = producer.send(message);
        System.out.println(send);
        // 关闭生产者
        producer.shutdown();
    }
}
